{{define "content"}}
<div x-data="manualPushData()" class="space-y-6">
    <!-- Page Header -->
    <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between">
        <div>
            <h1 class="text-2xl font-bold text-gray-900">手动推送</h1>
            <p class="mt-1 text-sm text-gray-500">手动选择客户和合作机构进行精准推送。</p>
        </div>
        <div class="mt-4 sm:mt-0 flex space-x-2">
            <a href="/push" 
               class="inline-flex items-center px-3 py-1.5 border border-gray-300 rounded-md shadow-sm text-xs font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500">
                <i class="fas fa-arrow-left mr-1 text-xs"></i>
                返回推送管理
            </a>

        </div>
    </div>

    <!-- Push Form -->
    <div class="bg-white shadow rounded-lg">
        <div class="px-6 py-4 border-b border-gray-200">
            <div class="flex items-center justify-between">
                <div>
                    <h3 class="text-lg font-medium text-gray-900">推送设置</h3>
                    <p class="text-sm text-gray-500">选择要推送的客户和目标合作机构</p>
                </div>
                <div>
                    <!-- Execute Button -->
                    <button type="button" 
                            @click="executePush()"
                            :disabled="!selectedCustomer || selectedPartners.length === 0 || (pushing || false)"
                            class="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 disabled:opacity-50 disabled:cursor-not-allowed">
                        <i class="fas fa-paper-plane mr-2 text-sm" :class="(pushing || false) ? 'animate-pulse' : ''"></i>
                        <span x-text="(pushing || false) ? '推送中...' : '执行推送'"></span>
                    </button>
                </div>
            </div>
        </div>
        <div class="p-6">
            <div class="space-y-6">
                <!-- Customer Selection -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-4">选择客户 *</label>
                    
                    <!-- Search and Filter -->
                    <div class="mb-4">
                        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3">
                            <div>
                                <input type="text" 
                                       x-model="customerSearchQuery"
                                       @input="searchCustomers()"
                                       placeholder="搜索客户姓名或手机号"
                                       class="block w-full px-2 py-1.5 text-sm border border-gray-300 rounded shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
                            </div>
                            <div>
                                <select x-model="customerCityFilter" @change="filterCustomers()" 
                                        class="block w-full px-2 py-1.5 text-sm border border-gray-300 rounded shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
                                    <option value="">全部城市</option>
                                    <template x-for="city in cities" :key="city">
                                        <option :value="city" x-text="city"></option>
                                    </template>
                                </select>
                            </div>
                            <div>
                                <select x-model="customerSubjectFilter" @change="filterCustomers()" 
                                        class="block w-full px-2 py-1.5 text-sm border border-gray-300 rounded shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
                                    <option value="">全部学科</option>
                                    <template x-for="subject in subjects" :key="subject">
                                        <option :value="subject" x-text="subject"></option>
                                    </template>
                                </select>
                            </div>
                            <div>
                                <select x-model="customerTimeFilter" @change="filterCustomers()" 
                                        class="block w-full px-2 py-1.5 text-sm border border-gray-300 rounded shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
                                    <option value="">全部时间</option>
                                    <option value="today">今天</option>
                                    <option value="yesterday">昨天</option>
                                    <option value="week">本周</option>
                                    <option value="month">本月</option>
                                    <option value="quarter">本季度</option>
                                    <option value="year">今年</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <!-- Customer List -->
                    <div class="border border-gray-200 rounded-lg">
                        <div class="max-h-80 overflow-y-auto p-4 space-y-3">
                            <template x-for="customer in customerPaginatedList" :key="customer.id">
                                <div class="bg-white border border-gray-200 rounded-lg p-4 hover:border-blue-300 hover:shadow-md transition-all duration-200 cursor-pointer"
                                     :class="selectedCustomer?.id === customer.id ? 'border-blue-500 bg-blue-50 shadow-md' : ''"
                                     @click="selectCustomer(customer)">
                                    <div class="flex items-center space-x-3">
                                        <input type="radio" 
                                               :checked="selectedCustomer?.id === customer.id"
                                               class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300">
                                        
                                        <!-- 客户头像 -->
                                        <div class="flex-shrink-0">
                                            <div class="h-10 w-10 rounded-full bg-gradient-to-r from-blue-400 to-blue-600 flex items-center justify-center shadow-md">
                                                <svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path>
                                                </svg>
                                            </div>
                                        </div>
                                        
                                        <div class="flex-1 min-w-0">
                                            <!-- 客户信息单行显示 -->
                                            <div class="flex items-center justify-between">
                                                <div class="flex items-center space-x-3 text-sm flex-wrap">
                                                    <div class="flex items-center">
                                                        <svg class="w-3 h-3 mr-1 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path>
                                                        </svg>
                                                        <span class="text-gray-500 text-xs mr-1">姓名:</span>
                                                        <span class="font-semibold text-gray-900" x-text="customer.name"></span>
                                                    </div>
                                                    
                                                    <div class="flex items-center text-gray-600">
                                                        <svg class="w-3 h-3 mr-1 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"></path>
                                                        </svg>
                                                        <span class="text-gray-500 text-xs mr-1">电话:</span>
                                                        <span x-text="customer.phone || '未填写'"></span>
                                                    </div>
                                                    
                                                    <div class="flex items-center text-gray-600">
                                                        <svg class="w-3 h-3 mr-1 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path>
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path>
                                                        </svg>
                                                        <span class="text-gray-500 text-xs mr-1">城市:</span>
                                                        <span x-text="customer.city || '未填写'"></span>
                                                    </div>
                                                    
                                                    <div class="flex items-center text-gray-600">
                                                        <svg class="w-3 h-3 mr-1 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"></path>
                                                        </svg>
                                                        <span class="text-gray-500 text-xs mr-1">科目:</span>
                                                        <span x-text="customer.subject || '未填写'"></span>
                                                    </div>
                                                    
                                                    <div class="flex items-center text-gray-600" x-show="customer.grade">
                                                        <svg class="w-3 h-3 mr-1 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 14l9-5-9-5-9 5 9 5z"></path>
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z"></path>
                                                        </svg>
                                                        <span class="text-gray-500 text-xs mr-1">年级:</span>
                                                        <span x-text="customer.grade"></span>
                                                    </div>
                                                    
                                                    <div class="flex items-center text-gray-600" x-show="customer.source">
                                                        <svg class="w-3 h-3 mr-1 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                                                        </svg>
                                                        <span class="text-gray-500 text-xs mr-1">来源:</span>
                                                        <span class="text-xs" x-text="customer.source"></span>
                                                    </div>
                                                    
                                                    <div class="flex items-center text-gray-600" x-show="customer.notes">
                                                        <svg class="w-3 h-3 mr-1 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-1.586l-4 4z"></path>
                                                        </svg>
                                                        <span class="text-gray-500 text-xs mr-1">备注:</span>
                                                        <span class="text-xs" x-text="customer.notes.length > 30 ? customer.notes.substring(0, 30) + '...' : customer.notes"></span>
                                                    </div>
                                                </div>
                                                
                                                <span class="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium ml-2 flex-shrink-0"
                                                      :class="{
                                                        'bg-green-100 text-green-800': customer.status === 'enrolled',
                                                        'bg-blue-100 text-blue-800': customer.status === 'interested',
                                                        'bg-yellow-100 text-yellow-800': customer.status === 'contacted',
                                                        'bg-gray-100 text-gray-800': customer.status === 'new',
                                                        'bg-red-100 text-red-800': customer.status === 'invalid'
                                                      }"
                                                      x-text="{
                                                        'enrolled': '已报名',
                                                        'interested': '有意向',
                                                        'contacted': '已联系',
                                                        'new': '新客户',
                                                        'invalid': '无效'
                                                      }[customer.status] || customer.status"></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </template>
                            
                            <div class="text-center py-8" x-show="customerPaginatedList.length === 0 && !loadingCustomers">
                                <i class="fas fa-users text-4xl text-gray-400 mb-4"></i>
                                <p class="text-gray-500">暂无符合条件的客户</p>
                            </div>

                            <div class="text-center py-8" x-show="loadingCustomers">
                                <i class="fas fa-spinner fa-spin text-4xl text-gray-400 mb-4"></i>
                                <p class="text-gray-500">正在加载客户数据...</p>
                            </div>
                        </div>
                        
                        <!-- Customer Pagination -->
                        <div class="px-4 py-3 border-t border-gray-200 flex items-center justify-between" x-show="customerTotalPages > 1">
                            <div class="text-sm text-gray-700">
                                显示第 <span x-text="(customerCurrentPage - 1) * customerPageSize + 1"></span> 到 
                                <span x-text="Math.min(customerCurrentPage * customerPageSize, customerTotal)"></span> 条，
                                共 <span x-text="customerTotal"></span> 条记录
                            </div>
                            <div class="flex items-center space-x-1">
                                <button @click="prevCustomerPage()" 
                                        :disabled="customerCurrentPage === 1"
                                        :class="customerCurrentPage === 1 ? 'opacity-50 cursor-not-allowed' : 'hover:bg-gray-100'"
                                        class="px-2 py-1 border border-gray-300 rounded text-xs">
                                    上一页
                                </button>
                                <template x-for="page in Array.from({length: customerTotalPages}, (_, i) => i + 1)" :key="page">
                                    <button @click="goToCustomerPage(page)"
                                            :class="page === customerCurrentPage ? 'bg-blue-500 text-white' : 'hover:bg-gray-100'"
                                            class="px-2 py-1 border border-gray-300 rounded text-xs min-w-[24px]"
                                            x-text="page"></button>
                                </template>
                                <button @click="nextCustomerPage()" 
                                        :disabled="customerCurrentPage === customerTotalPages"
                                        :class="customerCurrentPage === customerTotalPages ? 'opacity-50 cursor-not-allowed' : 'hover:bg-gray-100'"
                                        class="px-2 py-1 border border-gray-300 rounded text-xs">
                                    下一页
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Partner Selection -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-2">选择合作机构 *</label>
                    <div class="relative">
                        <button type="button" 
                                @click="showPartnerModal = true"
                                class="relative w-full bg-white border border-gray-300 rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-pointer focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 min-h-[40px]">
                            <div class="block" x-show="selectedPartners.length === 0">
                                <span class="text-gray-500">请选择合作机构</span>
                            </div>
                            <div class="flex flex-wrap gap-1" x-show="selectedPartners.length > 0">
                                <template x-for="partner in selectedPartners" :key="partner.id">
                                    <span class="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
                                        <span x-text="partner.name"></span>
                                        <button @click.stop="togglePartnerSelection(partner)" class="ml-1 text-blue-600 hover:text-blue-800">
                                            <i class="fas fa-times text-xs"></i>
                                        </button>
                                    </span>
                                </template>
                            </div>
                            <span class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
                                <i class="fas fa-chevron-down text-gray-400"></i>
                            </span>
                        </button>
                    </div>
                    <div x-show="selectedPartners.length > 0" class="mt-2">
                        <div class="text-sm text-gray-700 mb-2 font-medium">已选择 <span x-text="selectedPartners.length"></span> 个合作机构:</div>
                        <div class="border border-gray-200 rounded-lg">
                            <div class="max-h-60 overflow-y-auto">
                                <!-- 表格头部 -->
                                <div class="bg-gray-50 px-4 py-3 border-b border-gray-200 sticky top-0">
                                    <div class="grid grid-cols-12 gap-4 text-xs font-medium text-gray-500 uppercase tracking-wider items-center">
                                        <div class="col-span-3 flex items-center">机构信息</div>
                                        <div class="col-span-3 flex items-center">联系信息</div>
                                        <div class="col-span-2 flex items-center">业务范围</div>
                                        <div class="col-span-2 flex items-center">合作统计</div>
                                        <div class="col-span-1 flex items-center">状态</div>
                                        <div class="col-span-1 flex items-center">操作</div>
                                    </div>
                                </div>
                                
                                <!-- 机构列表 -->
                                <div class="divide-y divide-gray-200">
                                    <template x-for="partner in selectedPartners" :key="partner.id">
                                        <div class="px-4 py-4 hover:bg-gray-50 transition-colors duration-150 bg-blue-50 border-l-4 border-blue-500">
                                            <div class="grid grid-cols-12 gap-4 items-center">
                                                <!-- 机构信息 -->
                                                <div class="col-span-3">
                                                    <div class="flex items-center">
                                                        <div class="flex-shrink-0 h-10 w-10">
                                                            <div class="h-10 w-10 rounded-lg bg-gradient-to-r from-blue-500 to-purple-600 flex items-center justify-center text-white font-bold text-sm" 
                                                                 x-text="partner.name ? partner.name.charAt(0) : 'N'"></div>
                                                        </div>
                                                        <div class="ml-3">
                                                            <div class="text-sm font-medium text-gray-900" x-text="partner.name || '未知机构'"></div>
                                                            <div class="text-xs text-gray-500" x-text="partner.description ? (partner.description.length > 30 ? partner.description.substring(0, 30) + '...' : partner.description) : '暂无描述'"></div>
                                                            <div class="text-xs text-gray-500 mt-1" x-text="'ID: ' + partner.id"></div>
                                                        </div>
                                                    </div>
                                                </div>
                                                
                                                <!-- 联系信息 -->
                                                <div class="col-span-3">
                                                    <div class="space-y-1">
                                                        <div class="text-sm text-gray-900 flex items-center">
                                                            <svg class="w-3 h-3 mr-2 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path>
                                                            </svg>
                                                            <span x-text="partner.contact || partner.contact_person || '未填写'" class="truncate"></span>
                                                        </div>
                                                        <div class="text-sm text-gray-500 flex items-center">
                                                            <svg class="w-3 h-3 mr-2 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"></path>
                                                            </svg>
                                                            <span x-text="partner.phone || partner.contact_phone || '未填写'" class="truncate"></span>
                                                        </div>
                                                        <div class="text-sm text-gray-500 flex items-center" x-show="partner.email">
                                                            <svg class="w-3 h-3 mr-2 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 4.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>
                                                            </svg>
                                                            <span x-text="partner.email" class="truncate"></span>
                                                        </div>
                                                    </div>
                                                </div>
                                                
                                                <!-- 业务范围 -->
                                                <div class="col-span-2">
                                                    <div class="space-y-1">
                                                        <div class="text-sm text-gray-900">
                                                            <span x-text="partner.subjects || '未填写'"></span>
                                                        </div>
                                                        <div class="text-sm text-gray-500 flex items-center">
                                                            <svg class="w-3 h-3 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path>
                                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path>
                                                            </svg>
                                                            <span x-text="partner.city || '未填写'"></span>
                                                        </div>
                                                    </div>
                                                </div>
                                                
                                                <!-- 合作统计 -->
                                                <div class="col-span-2">
                                                    <div class="space-y-1">
                                                        <div class="flex items-center text-sm">
                                                            <div class="w-2 h-2 bg-blue-500 rounded-full mr-2"></div>
                                                            <span class="text-gray-600">推送：</span>
                                                            <span class="font-medium ml-1" x-text="partner.push_count || partner.total_pushes || '0'"></span>
                                                        </div>
                                                        <div class="flex items-center text-sm">
                                                            <div class="w-2 h-2 bg-green-500 rounded-full mr-2"></div>
                                                            <span class="text-gray-600">成功：</span>
                                                            <span class="font-medium ml-1" x-text="partner.success_count || partner.successful_pushes || '0'"></span>
                                                        </div>
                                                    </div>
                                                </div>
                                                
                                                <!-- 状态 -->
                                                <div class="col-span-1">
                                                    <span class="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium"
                                                          :class="{
                                                            'bg-green-100 text-green-800': partner.status === 'active',
                                                            'bg-red-100 text-red-800': partner.status === 'inactive',
                                                            'bg-yellow-100 text-yellow-800': partner.status === 'pending',
                                                            'bg-gray-100 text-gray-800': !partner.status
                                                          }"
                                                          x-text="{
                                                            'active': '活跃',
                                                            'inactive': '停用',
                                                            'pending': '待审核'
                                                          }[partner.status] || '未知'"></span>
                                                </div>
                                                
                                                <!-- 操作 -->
                                                <div class="col-span-1">
                                                    <button @click="togglePartnerSelection(partner)" 
                                                            class="text-red-500 hover:text-red-700 hover:bg-red-50 p-1 rounded transition-colors duration-150"
                                                            title="移除">
                                                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
                                                        </svg>
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    </template>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Push Notes -->
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-2">推送摘要 *</label>
                    <textarea x-model="pushNotes" 
                              rows="6" 
                              placeholder="请输入推送摘要信息（必填）"
                              required
                              class="block w-full px-3 py-2 text-sm border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500"></textarea>
                </div>

                <!-- Information Text -->
                <div>
                    <div class="text-sm text-gray-500">
                        <p>确认推送信息无误后，点击推送按钮执行操作。</p>
                    </div>
                </div>
            </div>
        </div>
    </div>



    <!-- Partner Selection Modal -->
    <div x-show="showPartnerModal" 
         x-transition:enter="ease-out duration-300" 
         x-transition:enter-start="opacity-0" 
         x-transition:enter-end="opacity-100" 
         x-transition:leave="ease-in duration-200" 
         x-transition:leave-start="opacity-100" 
         x-transition:leave-end="opacity-0"
         class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50" 
         style="display: none;">
        <div @click.stop class="relative top-10 mx-auto p-4 border container max-h-[80vh] shadow-lg rounded-md bg-white flex flex-col">
            <div>
                <div class="flex items-center justify-between mb-4">
                    <h3 class="text-lg font-medium text-gray-900">选择合作机构</h3>
                    <button @click="closePartnerModal()" class="text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-full p-1 w-8 h-8 flex items-center justify-center">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
                        </svg>
                    </button>
                </div>
                
                <!-- Search and Filter -->
                <div class="mb-4">
                    <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                        <div>
                            <input type="text" 
                                   x-model="partnerSearchQuery"
                                   @input="searchPartners()"
                                   placeholder="搜索机构名称"
                                   class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
                        </div>
                        <div>
                            <select x-model="partnerCityFilter" @change="filterPartners()" 
                                    class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
                                <option value="">全部城市</option>
                                <template x-for="city in partnerCities" :key="city">
                                    <option :value="city" x-text="city"></option>
                                </template>
                            </select>
                        </div>
                        <div>
                            <select x-model="partnerSubjectFilter" @change="filterPartners()" 
                                    class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500">
                                <option value="">全部学科</option>
                                <template x-for="subject in partnerSubjects" :key="subject">
                                    <option :value="subject" x-text="subject"></option>
                                </template>
                            </select>
                        </div>
                    </div>
                </div>

                <!-- Partner List -->
                <div class="border border-gray-200 rounded-lg">
                    <div class="flex-1 overflow-y-auto" style="max-height: 60vh;">
                        <!-- 表格头部 -->
                        <div class="bg-gray-50 px-4 py-3 border-b border-gray-200">
                            <div class="grid grid-cols-12 gap-4 text-xs font-medium text-gray-500 uppercase tracking-wider items-center">
                                <div class="col-span-1 flex items-center">选择</div>
                                <div class="col-span-3 flex items-center">机构信息</div>
                                <div class="col-span-3 flex items-center">联系信息</div>
                                <div class="col-span-2 flex items-center">业务范围</div>
                                <div class="col-span-2 flex items-center">合作统计</div>
                                <div class="col-span-1 flex items-center">状态</div>
                            </div>
                        </div>
                        
                        <!-- 机构列表 -->
                        <div class="divide-y divide-gray-200">
                            <template x-for="partner in partnerPaginatedList" :key="partner.id">
                                <div class="px-4 py-4 hover:bg-gray-50 transition-colors duration-150 cursor-pointer"
                                     :class="selectedPartners.some(p => p.id === partner.id) ? 'bg-blue-50 border-l-4 border-blue-500' : ''"
                                     @click="togglePartnerSelection(partner)">
                                    <div class="grid grid-cols-12 gap-4 items-center">
                                        <!-- 选择框 -->
                                        <div class="col-span-1 flex items-center justify-center">
                                            <input type="checkbox" 
                                                   :checked="selectedPartners.some(p => p.id === partner.id)"
                                                   @change="togglePartnerSelection(partner)"
                                                   class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
                                        </div>
                                        
                                        <!-- 机构信息 -->
                                        <div class="col-span-3">
                                            <div class="flex items-center">
                                                <div class="flex-shrink-0 h-10 w-10">
                                                    <div class="h-10 w-10 rounded-lg bg-gradient-to-r from-blue-500 to-purple-600 flex items-center justify-center text-white font-bold text-sm" 
                                                         x-text="partner.name ? partner.name.charAt(0) : 'N'"></div>
                                                </div>
                                                <div class="ml-3">
                                                    <div class="text-sm font-medium text-gray-900" x-text="partner.name || '未知机构'"></div>
                                                    <div class="text-xs text-gray-500" x-text="partner.description ? (partner.description.length > 30 ? partner.description.substring(0, 30) + '...' : partner.description) : '暂无描述'"></div>
                                                    <div class="text-xs text-gray-500 mt-1" x-text="'ID: ' + partner.id"></div>
                                                </div>
                                            </div>
                                        </div>
                                        
                                        <!-- 联系信息 -->
                                        <div class="col-span-3">
                                            <div class="space-y-1">
                                                <div class="text-sm text-gray-900 flex items-center">
                                                    <svg class="w-3 h-3 mr-2 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path>
                                                    </svg>
                                                    <span x-text="partner.contact || partner.contact_person || '未填写'" class="truncate"></span>
                                                </div>
                                                <div class="text-sm text-gray-500 flex items-center">
                                                    <svg class="w-3 h-3 mr-2 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"></path>
                                                    </svg>
                                                    <span x-text="partner.phone || partner.contact_phone || '未填写'" class="truncate"></span>
                                                </div>
                                                <div class="text-sm text-gray-500 flex items-center" x-show="partner.email">
                                                    <svg class="w-3 h-3 mr-2 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 4.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>
                                                    </svg>
                                                    <span x-text="partner.email" class="truncate"></span>
                                                </div>
                                            </div>
                                        </div>
                                        
                                        <!-- 业务范围 -->
                                        <div class="col-span-2">
                                            <div class="space-y-1">
                                                <div class="text-sm text-gray-900">
                                                    <span x-text="partner.subjects || '未填写'"></span>
                                                </div>
                                                <div class="text-sm text-gray-500 flex items-center">
                                                    <svg class="w-3 h-3 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path>
                                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path>
                                                    </svg>
                                                    <span x-text="partner.city || '未填写'"></span>
                                                </div>
                                            </div>
                                        </div>
                                        
                                        <!-- 合作统计 -->
                                        <div class="col-span-2">
                                            <div class="space-y-1">
                                                <div class="flex items-center text-sm">
                                                    <div class="w-2 h-2 bg-blue-500 rounded-full mr-2"></div>
                                                    <span class="text-gray-600">推送：</span>
                                                    <span class="font-medium ml-1" x-text="partner.push_count || partner.total_pushes || '0'"></span>
                                                </div>
                                                <div class="flex items-center text-sm">
                                                    <div class="w-2 h-2 bg-green-500 rounded-full mr-2"></div>
                                                    <span class="text-gray-600">成功：</span>
                                                    <span class="font-medium ml-1" x-text="partner.success_count || '0'"></span>
                                                </div>
                                                <div class="flex items-center text-sm">
                                                    <div class="w-2 h-2 bg-purple-500 rounded-full mr-2"></div>
                                                    <span class="text-gray-600">成功率：</span>
                                                    <span class="font-medium ml-1" 
                                                          :class="(partner.push_count > 0 ? ((partner.success_count / partner.push_count) * 100) : 0) >= 80 ? 'text-green-600' : (partner.push_count > 0 ? ((partner.success_count / partner.push_count) * 100) : 0) >= 60 ? 'text-yellow-600' : 'text-red-600'" 
                                                          x-text="partner.success_rate || (partner.push_count > 0 ? ((partner.success_count / partner.push_count) * 100).toFixed(1) + '%' : '0%')"></span>
                                                </div>
                                            </div>
                                        </div>
                                        
                                        <!-- 状态 -->
                                        <div class="col-span-1">
                                            <div class="flex flex-col space-y-1">
                                                <span class="inline-flex px-2 py-1 text-xs font-semibold rounded-full" 
                                                      :class="partner.status === 'active' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'">
                                                    <svg :class="partner.status === 'active' ? 'w-3 h-3 mr-1' : 'w-3 h-3 mr-1'" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                        <path x-show="partner.status === 'active'" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                                                        <path x-show="partner.status !== 'active'" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                                                    </svg>
                                                    <span x-text="partner.status === 'active' ? '活跃' : '停用'"></span>
                                                </span>
                                                <div class="text-xs text-gray-500" x-show="partner.created_at" x-text="'创建于 ' + new Date(partner.created_at).toLocaleDateString()"></div>
                                                <div class="text-xs text-gray-500" x-show="partner.updated_at" x-text="'更新于 ' + new Date(partner.updated_at).toLocaleDateString()"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </template>
                        </div>
                    </div>
                
                <!-- Partner Pagination -->

                  <div class="px-4 py-3 border-t border-gray-200 flex items-center justify-between" x-show="partnerTotalPages > 1">
                            <div class="text-sm text-gray-700">
                 
                        显示第 <span x-text="(partnerCurrentPage - 1) * partnerPageSize + 1"></span> 到 
                        <span x-text="Math.min(partnerCurrentPage * partnerPageSize, filteredPartners.length)"></span> 条，
                        共 <span x-text="filteredPartners.length"></span> 条记录
                    </div>
                    <div class="flex items-center space-x-1">
                        <button @click="prevPartnerPage()" 
                                :disabled="partnerCurrentPage === 1"
                                :class="partnerCurrentPage === 1 ? 'opacity-50 cursor-not-allowed' : 'hover:bg-gray-100'"
                                class="px-2 py-1 border border-gray-300 rounded text-xs">
                            上一页
                        </button>
                        <template x-for="page in Array.from({length: partnerTotalPages}, (_, i) => i + 1)" :key="page">
                            <button @click="goToPartnerPage(page)"
                                    :class="page === partnerCurrentPage ? 'bg-blue-500 text-white' : 'hover:bg-gray-100'"
                                    class="px-2 py-1 border border-gray-300 rounded text-xs min-w-[24px]"
                                    x-text="page"></button>
                        </template>
                        <button @click="nextPartnerPage()" 
                                :disabled="partnerCurrentPage === partnerTotalPages"
                                :class="partnerCurrentPage === partnerTotalPages ? 'opacity-50 cursor-not-allowed' : 'hover:bg-gray-100'"
                                class="px-2 py-1 border border-gray-300 rounded text-xs">
                            下一页
                        </button>
                    </div>
                </div>

                <div class="text-center py-8" x-show="partnerPaginatedList.length === 0 && !loadingPartners">
                    <i class="fas fa-building text-4xl text-gray-400 mb-4"></i>
                    <p class="text-gray-500">暂无符合条件的合作机构</p>
                </div>

                <div class="text-center py-8" x-show="loadingPartners">
                    <i class="fas fa-spinner fa-spin text-4xl text-gray-400 mb-4"></i>
                    <p class="text-gray-500">正在加载机构数据...</p>
                </div>
                    </div>
                    
                    <!-- 弹窗底部按钮 -->
                    <div class="flex items-center justify-between p-4 border-t border-gray-200 bg-gray-50">
                        <div class="text-sm text-gray-600">
                            已选择 <span x-text="selectedPartners.length"></span> 个合作机构
                        </div>
                        <div class="flex space-x-2">
                            <button @click="selectedPartners = []" 
                                    x-show="selectedPartners.length > 0"
                                    class="px-3 py-2 text-sm text-gray-600 hover:text-gray-800">
                                清空选择
                            </button>
                            <button @click="closePartnerModal()" 
                                    class="px-4 py-2 bg-blue-600 text-white text-sm rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500">
                                确认选择
                            </button>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>


</div>

<script>
    function manualPushData() {
        return {
            pushing: false,
            loadingCustomers: false,
            loadingPartners: false,
            showPartnerModal: false,

            
            selectedCustomer: null,
            selectedPartners: [],
            pushNotes: '',
            
            customers: [],
            filteredCustomers: [],
            customerTotal: 0, // API返回的客户总数
            customerSearchQuery: '',
            customerCityFilter: '',
            customerSubjectFilter: '',
            customerTimeFilter: '',
            
            // 客户分页
            customerCurrentPage: 1,
            customerPageSize: 20,
            customerTotalPages: 0,
            customerPaginatedList: [],
            
            partners: [],
            filteredPartners: [],
            partnerSearchQuery: '',
            partnerCityFilter: '',
            partnerSubjectFilter: '',
            
            // 合作机构分页
            partnerCurrentPage: 1,
            partnerPageSize: 20,
            partnerTotalPages: 0,
            partnerPaginatedList: [],
            
            cities: [],
            subjects: [],
            partnerCities: [],
            partnerSubjects: [],
            
            init() {
                this.loadCustomers();
                this.loadPartners();
                this.loadFilters();
            },
            
            async loadCustomers(page = 1) {
                this.loadingCustomers = true;
                try {
                    const token = localStorage.getItem('token');
                    
                    // 构建查询参数
                    const params = new URLSearchParams({
                        size: this.customerPageSize,
                        page: page,
                        pushed: 0
                    });
                    
                    // 添加筛选条件
                    if (this.customerSearchQuery.trim()) {
                        params.append('search', this.customerSearchQuery.trim());
                    }
                    if (this.customerCityFilter) {
                        params.append('city', this.customerCityFilter);
                    }
                    if (this.customerSubjectFilter) {
                        params.append('subject', this.customerSubjectFilter);
                    }
                    // 时间筛选暂时在前端处理
                    // if (this.customerTimeFilter) {
                    //     params.append('time_filter', this.customerTimeFilter);
                    // }
                    
                    const response = await fetch(`/api/v1/customers?${params.toString()}`);
                    
                    if (response.ok) {
                        const data = await response.json();
                        console.log('Customer API Response:', data);
                        if (data.code === 200) {
                            // 检查数据结构
                            console.log('Customer data structure:', data.data);
                            this.customers = data.data || [];
                            this.customerTotal = data.total || 0; // 保存API返回的总数
                            console.log('Loaded customers:', this.customers);
                            
                            // 应用时间筛选（在前端处理）
                            this.applyTimeFilter();
                            
                            this.customerCurrentPage = page;
                            this.updateCustomerPagination();
                        } else {
                            console.error('API returned error:', data);
                            showToast(data.message || '加载客户数据失败', 'error');
                        }
                    } else {
                        console.error('HTTP error:', response.status, response.statusText);
                        showToast('网络请求失败', 'error');
                    }
                } catch (error) {
                    console.error('Failed to load customers:', error);
                    showToast('加载客户数据失败', 'error');
                } finally {
                    this.loadingCustomers = false;
                }
            },
            
            async loadPartners() {
                this.loadingPartners = true;
                try {
                    const token = localStorage.getItem('token');
                    // 不限制状态，获取所有机构数据
                    const response = await fetch('/api/v1/partners?size=1000', {
                        headers: {
                            'Authorization': 'Bearer ' + token
                        }
                    });
                    
                    if (response.ok) {
                        const data = await response.json();
                        console.log('Partner API Response:', data);
                        if (data.code === 200) {
                            // 检查数据结构
                            console.log('Partner data structure:', data.data);
                            this.partners = data.data.items || data.data || [];
                            console.log('Loaded partners:', this.partners);
                            this.filteredPartners = this.partners;
                            this.updatePartnerPagination();
                        } else {
                            console.error('API returned error:', data);
                            showToast(data.message || '加载机构数据失败', 'error');
                        }
                    } else {
                        console.error('HTTP error:', response.status, response.statusText);
                        showToast('网络请求失败', 'error');
                    }
                } catch (error) {
                    console.error('Failed to load partners:', error);
                    showToast('加载机构数据失败', 'error');
                } finally {
                    this.loadingPartners = false;
                }
            },
            
            async loadFilters() {
                try {
                    const token = localStorage.getItem('token');
                    
                    // 加载客户筛选条件
                    const customerResponse = await fetch('/api/v1/customers/filters', {
                        headers: {
                            'Authorization': 'Bearer ' + token
                        }
                    });
                    
                    if (customerResponse.ok) {
                        const customerData = await customerResponse.json();
                        if (customerData.code === 200) {
                            this.cities = customerData.data.cities || [];
                            this.subjects = customerData.data.subjects || [];
                        }
                    }
                    
                    // 加载机构筛选条件
                    const partnerResponse = await fetch('/api/v1/partners/filters', {
                        headers: {
                            'Authorization': 'Bearer ' + token
                        }
                    });
                    
                    if (partnerResponse.ok) {
                        const partnerData = await partnerResponse.json();
                        if (partnerData.code === 200) {
                            this.partnerCities = partnerData.data.cities || [];
                            this.partnerSubjects = partnerData.data.subjects || [];
                        }
                    }
                } catch (error) {
                    console.error('Failed to load filters:', error);
                }
            },
            
            searchCustomers() {
                this.filterCustomers();
            },
            
            filterCustomers() {
                // 重置到第一页并重新加载数据
                this.customerCurrentPage = 1;
                this.loadCustomers(1);
            },
            
            applyTimeFilter() {
                let filtered = this.customers;
                
                if (this.customerTimeFilter) {
                    filtered = filtered.filter(customer => this.matchesTimeFilter(customer, this.customerTimeFilter));
                }
                
                this.filteredCustomers = filtered;
            },
            
            matchesTimeFilter(customer, timeFilter) {
                if (!customer.created_at) return false;
                
                const customerDate = new Date(customer.created_at);
                const now = new Date();
                const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
                
                switch (timeFilter) {
                    case 'today':
                        const todayEnd = new Date(today.getTime() + 24 * 60 * 60 * 1000);
                        return customerDate >= today && customerDate < todayEnd;
                    
                    case 'yesterday':
                        const yesterday = new Date(today.getTime() - 24 * 60 * 60 * 1000);
                        return customerDate >= yesterday && customerDate < today;
                    
                    case 'week':
                        const weekStart = new Date(today);
                        weekStart.setDate(today.getDate() - today.getDay());
                        return customerDate >= weekStart;
                    
                    case 'month':
                        const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);
                        return customerDate >= monthStart;
                    
                    case 'quarter':
                        const quarterMonth = Math.floor(now.getMonth() / 3) * 3;
                        const quarterStart = new Date(now.getFullYear(), quarterMonth, 1);
                        return customerDate >= quarterStart;
                    
                    case 'year':
                        const yearStart = new Date(now.getFullYear(), 0, 1);
                        return customerDate >= yearStart;
                    
                    default:
                        return true;
                }
            },
            
            updateCustomerPagination() {
                // 使用API返回的总数来计算分页
                this.customerTotalPages = Math.ceil(this.customerTotal / this.customerPageSize);
                // 当前页面的数据就是从API获取的数据
                this.customerPaginatedList = this.filteredCustomers;
            },
            
            goToCustomerPage(page) {
                if (page >= 1 && page <= this.customerTotalPages) {
                    this.loadCustomers(page);
                }
            },
            
            prevCustomerPage() {
                this.goToCustomerPage(this.customerCurrentPage - 1);
            },
            
            nextCustomerPage() {
                this.goToCustomerPage(this.customerCurrentPage + 1);
            },
            
            searchPartners() {
                this.filterPartners();
            },
            
            filterPartners() {
                let filtered = this.partners;
                
                if (this.partnerSearchQuery.trim()) {
                    const query = this.partnerSearchQuery.toLowerCase();
                    filtered = filtered.filter(partner => 
                        partner.name.toLowerCase().includes(query)
                    );
                }
                
                if (this.partnerCityFilter) {
                    filtered = filtered.filter(partner => partner.city === this.partnerCityFilter);
                }
                
                if (this.partnerSubjectFilter) {
                    filtered = filtered.filter(partner => 
                        partner.subjects && partner.subjects.includes(this.partnerSubjectFilter)
                    );
                }
                
                this.filteredPartners = filtered;
                this.partnerCurrentPage = 1;
                this.updatePartnerPagination();
            },
            
            updatePartnerPagination() {
                this.partnerTotalPages = Math.ceil(this.filteredPartners.length / this.partnerPageSize);
                const startIndex = (this.partnerCurrentPage - 1) * this.partnerPageSize;
                const endIndex = startIndex + this.partnerPageSize;
                this.partnerPaginatedList = this.filteredPartners.slice(startIndex, endIndex);
            },
            
            goToPartnerPage(page) {
                if (page >= 1 && page <= this.partnerTotalPages) {
                    this.partnerCurrentPage = page;
                    this.updatePartnerPagination();
                }
            },
            
            prevPartnerPage() {
                this.goToPartnerPage(this.partnerCurrentPage - 1);
            },
            
            nextPartnerPage() {
                this.goToPartnerPage(this.partnerCurrentPage + 1);
            },
            
            selectCustomer(customer) {
                this.selectedCustomer = customer;
                
                // 自动生成摘要
                if (!customer) return;
                
                const summary = [];
                
                // 基本信息
                if (customer.name) {
                    summary.push(`客户：${customer.name}`);
                }
                
                if (customer.phone) {
                    summary.push(`电话：${customer.phone}`);
                }
                
                if (customer.city) {
                    summary.push(`城市：${customer.city}`);
                }
                
                if (customer.subject) {
                    summary.push(`科目：${customer.subject}`);
                }
                
                if (customer.grade) {
                    summary.push(`年级：${customer.grade}`);
                }
                
                // 状态信息
                if (customer.status) {
                    const statusMap = {
                        'enrolled': '已报名',
                        'interested': '有意向',
                        'contacted': '已联系',
                        'new': '新客户',
                        'invalid': '无效'
                    };
                    summary.push(`状态：${statusMap[customer.status] || customer.status}`);
                }
                
                // 来源信息
                if (customer.source) {
                    summary.push(`来源：${customer.source}`);
                }
                
                // 备注信息
                if (customer.notes && customer.notes.trim()) {
                    summary.push(`备注：${customer.notes}`);
                }
                
                // 生成最终摘要（换行分隔）
                const finalSummary = summary.join('\n');
                
                // 每次点击都清空推送摘要，然后设置新的摘要
                this.pushNotes = finalSummary;
            },
            
            togglePartnerSelection(partner) {
                const index = this.selectedPartners.findIndex(p => p.id === partner.id);
                if (index > -1) {
                    this.selectedPartners.splice(index, 1);
                } else {
                    this.selectedPartners.push(partner);
                }
            },
            
            closePartnerModal() {
                this.showPartnerModal = false;
                this.partnerSearchQuery = '';
                this.partnerCityFilter = '';
                this.partnerSubjectFilter = '';
                this.filteredPartners = this.partners;
                this.partnerCurrentPage = 1;
                this.updatePartnerPagination();
            },
            
            async executePush() {
                if (!this.selectedCustomer || this.selectedPartners.length === 0) {
                    showToast('请选择客户和至少一个合作机构', 'error');
                    return;
                }
                
                this.pushing = true;
                try {
                    const token = localStorage.getItem('token');
                    
                    // 批量推送到多个合作机构
                    const pushPromises = this.selectedPartners.map(partner => 
                        fetch('/api/v1/push/manual', {
                            method: 'POST',
                            body: JSON.stringify({
                                customer_id: this.selectedCustomer.id,
                                partner_id: partner.id,
                                notes: this.pushNotes
                            })
                        })
                    );
                    
                    const responses = await Promise.all(pushPromises);
                    const results = await Promise.all(responses.map(r => r.json()));
                    
                    const successCount = results.filter(r => r.code === 200).length;
                    const totalCount = this.selectedPartners.length;
                    
                    if (successCount === totalCount) {
                        showToast(`成功推送到 ${successCount} 个合作机构`, 'success');
                    } else if (successCount > 0) {
                        showToast(`成功推送到 ${successCount}/${totalCount} 个合作机构`, 'warning');
                    } else {
                        showToast('推送失败', 'error');
                    }
                    
                    // 重置表单
                    this.selectedCustomer = null;
                    this.selectedPartners = [];
                    this.pushNotes = '';
                    
                    // 刷新客户列表数据
                    await this.loadCustomers(this.customerCurrentPage);
                    
                    // 跳转到推送记录页面
                    setTimeout(() => {
                        //window.location.href = '/push/records';
                    }, 1500);
                    
                } catch (error) {
                    console.error('Manual push failed:', error);
                    showToast('手动推送失败', 'error');
                } finally {
                    this.pushing = false;
                }
            }
        }
    }
</script>
{{end}}